<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 16.12.2014
 * Time: 18:44
 */

namespace FlashMessages\Workers;


use FlashMessages\Queue\Worker;
use NotificationDelivery\Queue;
use Pinenut\Queue\ProcessingQueue;

class FlashMessageSendAction extends Worker {

	/**
	 * Создает уведомления об отправке нового flash-сообщения
	 *
	 * @param ProcessingQueue $item - элемент очереди
	 * @return bool
	 */
	public function process(ProcessingQueue $item)
	{
		$flashMessageId = (string)$item->data['flashMessageId'];
		$targetProfileId = (string)$item->data['targetProfileId'];

		# Добавляем в очередь новое уведомление
		Queue::enqueue(
			[
				'type' => \NotificationDeliveryConfig::TYPE_SEND_TO_RECEIVER,
				'subscriber' => $targetProfileId,
				'data' =>
					[
						'eventName' => 'flashMessageNew',
						'eventData' => [
							'flashMessageId' => $flashMessageId,
						],
					],
			]
		);

		return true;
	}
}